const app = getApp()

Page({
  data: {
    inputValue: '',
    inputValue2: ''
  },
  onLoad: function (options) {

  },
  async handleUnfinish (e) {
    wx.showLoading()
    const name = e.currentTarget.dataset.name
    const array = ['', '就业培训', '鉴赏师培训', '鉴定师培训', '青少年教育']
    let curriculumType = 0
    array.forEach((item, index) => { if (item === name) curriculumType = index })
    const res = await app.http.get('/api/v1/getCurriculum?curriculumType=' + curriculumType)
    if (res.code == 0) {
      const suffix = res.data.file_url.substr(res.data.file_url.lastIndexOf('.') + 1)
      if (suffix === 'png' || suffix === 'jpg') {
        const img = await wx.previewImage({
          urls: [res.data.file_url]
        })
        wx.hideLoading()
        return
      }
      wx.downloadFile({
        url: res.data.file_url,
        success (res) {
          if (res.statusCode === 200) {
            wx.openDocument({
              filePath: res.tempFilePath,
              // fileType: 'xlsx',
              showMenu: true,
              success: result => {
                wx.hideLoading()
                console.log("打开文档成功")
              },
              fail: err => {
                // console.log(err.errMsg)
                app.helper.msg(err.errMsg)
              }
            })
          }
        }
      })
    } else {
      app.helper.msg(res.message)
    }
    // setTimeout(function () {
    //   wx.hideLoading()
    // }, 2000)
  },
  async handleSearch (e) {
    this.setData({ inputValue: '', inputValue2: '' })
    const res = await app.http.get('/api/v1/getZhenshu?num=' + e.currentTarget.dataset.value)
    // console.log(res)
    if (res.code == 0) {
      wx.setStorageSync('zs', res.data)
      wx.navigateTo({
        url: '/pages/zs/zs',
      })
    } else {
      app.helper.msg(res.message)
    }
    // if (this.data.inputValue.length) {
    //   app.helper.msg('未查到相关证书')
    //   // wx.navigateTo({ url: '/pages/result/index' })
    // } else {
    //   app.helper.msg('请输入证书编号')
    // }
  },
  toNorm(){
    wx.navigateTo({
      url: '/pages/norm/norm',
    })
  },
  toWay(){
    wx.navigateTo({
      url: '/pages/way/way',
    })
  },
  async toJossList1(e){
    const name = e.currentTarget.dataset.name
    const array = ['', '陶器', '瓷器', '玉器', '铜器', '古兵', '造像', '古币', '杂项']
    let category = 0
    array.forEach((item, index) => { if (item === name) category = index })
    wx.navigateTo({
      url: '/pages/jossList/jossList?category=' + category,
    })
  },
  toJossList2(){
    wx.navigateTo({
      url: '/pages/jossList/jossList?index=2',
    })
  },
  toJossList3(){
    wx.navigateTo({
      url: '/pages/jossList/jossList?index=3',
    })
  },
  toJossList4(){
    wx.navigateTo({
      url: '/pages/jossList/jossList?index=4',
    })
  },
  onShareAppMessage: function () {

  }
})